package com.sip.dbadapter.dao.impl;

import java.io.Serializable;
import java.util.List;

import com.sip.dbadapter.dao.domain.ScanTypeRest;
import com.sip.dbadapter.dao.interfaces.RestServiceDao;


public class RestServiceDaoImpl extends BusinessDaoImpl<ScanTypeRest, Serializable> implements RestServiceDao {

    
    
    @Override
    protected Class<ScanTypeRest> getDomainClass() {


        return ScanTypeRest.class;
    }

    @Override
    public  String getRestServiceURLByApiId(Long apiId) {

        String[] conditionParamNames= new String[] {"scanTypeId"};
        Object[] paramsValue= new Object[] {apiId};
        
      String conditionClause = "";
        String methodUrl;
                conditionClause = createConditionClause(conditionParamNames, conditionClause);
                List<Object> urlList =
                    (List<Object>) exec("select A.methodUrl from " + getDomainClass().getName() + " A where " + conditionClause, paramsValue);
                methodUrl= (String) urlList.get(0);
                return methodUrl;
    } 
    @Override
    public  ScanTypeRest getRestServiceByApiId(Long apiId) {

        String[] conditionParamNames= new String[] {"scanTypeId"};
        Object[] paramsValue= new Object[] {apiId};
        
      String conditionClause = "";
      ScanTypeRest scanTypeRestDomain;
                conditionClause = createConditionClause(conditionParamNames, conditionClause);
                List<Object> urlList =
                    (List<Object>) exec("select A from " + getDomainClass().getName() + " A where " + conditionClause, paramsValue);
                scanTypeRestDomain= (ScanTypeRest) urlList.get(0);
                return scanTypeRestDomain;
    } 

    private String createConditionClause(String[] conditionParamNames, String conditionClause) {

        for (String object : conditionParamNames) {
            if (conditionParamNames.length == 1) {
                conditionClause = "A." + object + "=?";
            } else {
                conditionClause += " and A." + object + "=?";
            }
        }

        return conditionClause;
    }


    
    
}
